//
//  YSResultView.m
//  Yaoyle
//
//  Created by ZhaoXudong on 14-10-11.
//  Copyright (c) 2014年 ZhaoXudong. All rights reserved.
//

#import "YSDieResultView.h"
#import "YSUi.h"
#import "UIViewExt.h"

static NSInteger space = 6;
static CGFloat  imageSize = 26;

@interface YSDieResultView () {
    UIImageView *talkView;
}

@end

@implementation YSDieResultView

- (id)initWithFrame:(CGRect)frame result:(NSString*)result
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        NSArray *array = [result componentsSeparatedByString:@"-"];
        NSInteger nIndex = 0;
        for (NSString *s in array) {
            NSString *imageName = [NSString stringWithFormat:@"bs_%@",s];
            
            UIImage *image = [UIImage imageNamed:imageName];
            UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
            imageView.frame = CGRectMake(nIndex * (space + imageSize), resultViewHeight - imageSize, imageSize, imageSize);
            [self addSubview:imageView];
            nIndex ++;
        }
        
        [self showAlertView];
    }
    return self;
}

- (void)showAlertView {
    NSString *msg = @"这是你摇出来的骰子";   //talk_bg
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, resultViewWidth, resultViewHeight - imageSize - 6)];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont systemFontOfSize:13];
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor blackColor];
    label.text = msg;
    
    UIImage *image = [UIImage imageNamed:@"talk_bg"];
    talkView = [[UIImageView alloc] initWithImage:image];
    talkView.frame = CGRectMake(0, 0, resultViewWidth - 6, resultViewHeight - imageSize);
    
    [talkView addSubview:label];
    [self addSubview:talkView];
}

- (void)hideAlertView {
    [UIView animateWithDuration:4 animations:^{
        talkView.alpha = 0;
    } completion:^(BOOL finished) {
        talkView.hidden = YES;
    }];
}
@end
